﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace IntelligentDecisioning.SharePoint.Logging
{
    /// <summary>
    /// 
    /// </summary>
    public class XMLLog: ILog
    {
        #region Data

        private XmlTextWriter xmlWriter;
        private TextWriter textWriter;

        #endregion

        #region Constructors

        public XMLLog()
        {
           textWriter = new StringWriter(new StringBuilder());
           xmlWriter = new XmlTextWriter(textWriter);

        }

        public String GetXmlString()
        {
            return  "<Log>" + textWriter.ToString() + "</Log>";
        }

        #endregion

        #region ILog Members

        public void WriteToLog(string message)
        {
            xmlWriter.WriteElementString("Info", message);
        }

        public void WriteToLog(string message, Exception e)
        {
            String errorMessage = message = e.Message;
            while(e.InnerException != null)
            {
                e = e.InnerException;
                message += " Inner Exception message: " + e.Message;
            }

            xmlWriter.WriteElementString("Error", errorMessage);
        }

        #endregion
    }


}
